﻿using MengLin.OOP.DesignPattern.WMS_LC4.Interface;
using MengLin.OOP.DesignPattern.WMS_LC4.Interface.Observer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.WMS_LC4
{
    /// <summary>
    /// 电视显示屏
    /// </summary>
    public class TVMonitoringScreen : IMonitoringScreen, IObserver
    {
        /// <summary>
        /// 显示气压
        /// </summary>
        /// <param name="pressure">气压</param>
        public void DisplayPressure(double pressure)
        {
            Console.WriteLine($"电视显示屏显示气压:{pressure}");
        }

        /// <summary>
        /// 显示温度
        /// </summary>
        /// <param name="temperature">温度</param>
        public void DisplayTemp(double temperature)
        {
            Console.WriteLine($"电视显示屏显示温度:{temperature}");
        }

        /// <summary>
        /// 更新显示温度/气压
        /// </summary>
        /// <param name="obj"></param>
        public void Update(object obj)
        {
            string[] strArray = obj.ToString().Split('|');
            if(strArray[0] == "temperature")
            {
                DisplayTemp(Convert.ToDouble(strArray[1]));
            }
            if (strArray[0] == "pressure")
            {
                DisplayPressure(Convert.ToDouble(strArray[1]));
            }
        }
    }
}
